/**
 * Created by win 10 on 2/7/2018.
 */
$(function () {
    var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,10}$/;
    $(".sure-password").click(function (e) {
        e = window.event || event;
        e.preventDefault();
        if (!$.cookie('FUND_USER_TOKEN')) {
            alert('请先登录');
        }
        var password = $("#last-password").val();
        var password1 = $("#password1").val();
        var password2 = $("#password2").val();
        if (!password || !password1 || !password2) {
            $(".mini-error").text("＊ 请将以上表单填写完整");
            return false;
        } else if (!reg.test(password1)) {
            $(".mini-error").text("＊ 密码格式错误");
            return false;
        } else if (password1 !== password2) {
            $(".mini-error").text("＊ 两次密码不一致");
            return false;
        } else {
            $.ajax({
                url: '/sichuansfc/fund/user/update.bs?password='+password+'&newPassword='+password1,
                type: 'get',
                headers: {'FUND_USER_TOKEN': $.cookie('FUND_USER_TOKEN')},
                success: function (data) {
                    if (data.status === 100000) {
                        $.cookie('FUND_USER_TOKEN', '', {expires: -1});
                        alert('密码修改成功，您需要重新登录');
                        location.href = '../html/index.html?update='+true;
                        // judgeLogin();
                        // $("#update").reset();
                    } else {
                        $(".mini-error").text(data.msg)
                    }
                },
                error: function () {
                    alert("服务器异常，请稍后重试")
                }
            })
        }
    })
})
function judgeLogin() {
    if ($.cookie("FUND_USER_TOKEN")) {
        $(".welcome-you > a").text('Hi, '+ window.localStorage.getItem('userName'))
        $(".login-out").css("display","none");
        $(".login-in").css("display","block");
    } else {
        $(".login-out").css("display","block");
        $(".login-in").css("display","none");
    }
}